package rpt

import (
	"gitee.com/alex_li/amazon-rpt/internal/db"
	"gitee.com/alex_li/amazon-rpt/internal/sdk/advertising"
)

// GenReq 构建报表请求, rptName: 指定名称, 如不指定, 默认使用 GenRptName
func GenReq(startDate, endDate string, rptTpl Template, report ...db.AmazonRpt) (req advertising.RptReq) {
	var name string
	if len(report) > 0 {
		name = report[0].Name
	} else {
		name = GenRptName()
	}
	req = advertising.RptReq{
		RptHeader: advertising.RptHeader{
			Name: name,
			DateDuration: advertising.DateDuration{
				StartDate: startDate,
				EndDate:   endDate,
			},
		},
		Config: advertising.RptConfig{
			AdProduct:    rptTpl.Product.Value,
			GroupBy:      rptTpl.Group,
			Columns:      rptTpl.GetFieldsName(),
			ReportTypeId: rptTpl.RptType,
			TimeUnit:     rptTpl.TimeUnit.Value,
			Format:       "GZIP_JSON",
			Filters:      rptTpl.Filters,
		},
	}
	return
}
